package cn.szq.concurrent.thread.stop;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * @ClassName: BlockingQueueTest
 * @Description:
 * @Author: szq
 * @Date: 2021-09-27 09:58:24
 */
public class BlockingQueueTest {

    public static void main(String[] args) {
        BlockingQueue<Object> queue = new ArrayBlockingQueue<>(10);

        Runnable producer = () ->{
            while (true){
                try {
                    queue.put(new Object());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };

        new Thread(producer).start();
        new Thread(producer).start();

        Runnable consumer = () ->{
            while (true){
                queue.remove();
            }
        };

        new Thread(consumer).start();
        new Thread(consumer).start();
    }
}
